﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC_Filter.Infrastructure
{
    public class ProfileResultAttribute:FilterAttribute,IResultFilter
    {
        private Stopwatch timer;
 

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            timer=Stopwatch.StartNew();
        }
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            timer.Stop();
            if (filterContext.Exception==null)
            {
                filterContext.HttpContext.Response.Write("<br>(result filter)The run time is "+timer.Elapsed.TotalMilliseconds);
            }
        }
    }
}